import { createAPI } from '@/utils/request'
import moment from 'moment';

// 获取学科列表
export const getsubList = params => createAPI(`/subjects`, 'get', params)

// 处理成功
//  .then(res => console.log('8',res.data))s
//  .then(res => res.data)
.then(res => ({

  counts:res.data.counts,
  items: res.data.items.map((d,i)=>({
    ...d,
    index: (params.page - 1) * params.pagesize + i + 1,
    isFrontDisplay: d.isFrontDisplay ? '是': '否',
    addDate: moment(d.addDate).format('YYYY-MM-DD H:mm:ss'),


  }))

}))

  // 处理错误
.catch(() => {});



// 学科添加
export const addsubList = data => createAPI(`/subjects`, 'post', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)


  // 处理错误
.catch(() => {});


// 学科修改
export const changeSubList = data => createAPI(`/subjects/${data.id}`, 'put', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)


  // 处理错误
.catch(() => {});


// 学科删除
export const deleteSubList = params => createAPI(`/subjects/${params.id}`, 'delete', params)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)


  // 处理错误
.catch(() => {});


// 目录列表
export const getdirectorysList = params => createAPI(`/directorys`, 'get', params)

// 处理成功
//  .then(res => console.log('8',res.data))s
//  .then(res => res.data)
 .then(res => ({

  counts:res.data.counts,
  items: res.data.items.map((d,i)=>({
    ...d,
    index: (params.page - 1) * params.pagesize + i + 1,
    state: d.state ? '已启用': '已禁用',
    addDate: moment(d.addDate).format('YYYY-MM-DD H:mm:ss'),
  }))
}))
  // 处理错误
.catch(() => {});


// 目录添加
export const addCatalog = data => createAPI(`/directorys`, 'post', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)


  // 处理错误
.catch(() => {});


// 目录状态(调启用禁用)
export const contentsState = data => createAPI(`/directorys/${data.id}/${data.state}`, 'post', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)


  // 处理错误
.catch(() => {});


// 目录修改
export const changeCatalog = data => createAPI(`/directorys/${data.id}`, 'put', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)


  // 处理错误
.catch(() => {});


// 目录删除
export const deleteCatalog = data => createAPI(`/directorys/${data.id}`, 'delete', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)


  // 处理错误
.catch(() => {});


// 获取标签列表
export const gettagsList = params => createAPI(`/tags`, 'get', params)

// 处理成功
//  .then(res => console.log('8',res.data))s
//  .then(res => res.data)
 .then(res => ({

  counts:res.data.counts,
  items: res.data.items.map((d,i)=>({
    ...d,
    index: (params.page - 1) * params.pagesize + i + 1,
    state: d.state ? '已启用': '已禁用',
    addDate: moment(d.addDate).format('YYYY-MM-DD H:mm:ss'),
  }))
}))


  // 处理错误
.catch(() => {});


// 标签添加
export const addTags = data => createAPI(`/tags`, 'post', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)

  // 处理错误
.catch(() => {});


// 标签状态 启用/禁用
export const changeTags = data => createAPI(`/tags/${data.id}/${data.state}`, 'post', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)

  // 处理错误
.catch(() => {});


// 7.7标签修改
export const amendTags = data => createAPI(`/tags/${data.id}`, 'put', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)

  // 处理错误
.catch(() => {});


// 7.9标签删除
export const deleteTags = data => createAPI(`/tags/${data.id}`, 'delete', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)

  // 处理错误
.catch(() => {});
